


/*GET CITIES BY REGION -- (Rahul)*/

$(document).ready(function(){
    $('#region').change(function(){ //any select change on the dropdown with id country trigger this code
        $("#city > option").remove(); //first of all clear select items
        var state_id = $('#region').val();  // here we are taking country id of the selected one.
      
       
        
         $("#city").removeAttr('disabled');
       
         
        var base_url = $('body').data('baseurl');
        
       // var url = base_url+"browse/location/getcity/"+state_id
       // alert(url)
        var img = base_url + "assets/img/ico/ajax-loader-mini.gif";
		$('#alert').html('<img src="' + img + '" />')
        
        $.ajax({
            type: "POST",
            url: base_url+"browse/location/getcity/"+state_id, //here we are calling our user controller and get_cities method with the country_id
            
            success: function($city) //we're calling the response json array 'cities'
            {
            	var opt1 = $('<option />'); // here we're creating a new select option with for each city
                opt1.val(0);
                opt1.text("--Select City--");
                
                $('#city').append(opt1); //here we will append these new select options to a dropdown with the id 'cities'
                
            	
                $.each($city,function(child_id,name) //here we're doing a foeach loop round each city with id as the key and city as the value
                {
                	var opt = $('<option />'); // here we're creating a new select option with for each city
                    opt.val(child_id);
                    opt.text(name);
                    $("#alert").html(opt).fadeIn('slow');
                    $('#city').append(opt); //here we will append these new select options to a dropdown with the id 'cities'
                });
            }

        });

    });
});

/*GET CITIES BY REGION -- (Rahul)*/
$(document).ready(function(){
    $('#statename').change(function(){ //any select change on the dropdown with id country trigger this code
        $("#city > option").remove(); //first of all clear select items
        var state_id = $('#statename').val();  // here we are taking country id of the selected one.
     //   alert(state_id);
         $("#city").removeAttr('disabled');
       
       
        var base_url = $('body').data('baseurl');
        
        var img = base_url + "assets/img/ico/ajax-loader-mini.gif";
		$('#alert').html('<img src="' + img + '" />')
      // alert(url);
        $.ajax({
            type: "GET",
            url: base_url+"browse/location/getcity/"+state_id, //here we are calling our user controller and get_cities method with the country_id
            
            success: function($city) //we're calling the response json array 'cities'
            {
            	var opt1 = $('<option />'); // here we're creating a new select option with for each city
                opt1.val(0);
                opt1.text("--Select City--");
                
                $('#city').append(opt1); //here we will append these new select options to a dropdown with the id 'cities'
                
            	
                $.each($city,function(child_id,name) //here we're doing a foeach loop round each city with id as the key and city as the value
                {
                	var opt = $('<option />'); // here we're creating a new select option with for each city
                    opt.val(child_id);
                    opt.text(name);
                    $("#alert").html(opt).fadeIn('slow');
                    $('#city').append(opt); //here we will append these new select options to a dropdown with the id 'cities'
                });
            }

        });

    });
});

/*GET SUB-CATEGORY BY PARENT -- (Rahul)*/

$(document).ready(function(){
    $('#category').change(function(){ //any select change on the dropdown with id country trigger this code
        $("#sub_category > option").remove(); //first of all clear select items
        var parent_id = $('#category').val();  // here we are taking country id of the selected one.
      
         $("#sub_category").removeAttr('disabled');
         
        var base_url = $('body').data('baseurl');
        
       // var url = base_url+"browse/location/getcity/"+state_id
       // alert(url)
        var img = base_url + "assets/img/ajax-loader2.gif";
		$('#alert').html('<img src="' + img + '" />')
        
        $.ajax({
            type: "POST",
            url: base_url+"browse/category/getchild/"+parent_id, //here we are calling our user controller and get_cities method with the country_id
            
            success: function($subcategory) //we're calling the response json array 'cities'
            {
            	var opt1 = $('<option />'); // here we're creating a new select option with for each city
                opt1.val(0);
                opt1.text("--Select Sub-Category--");
                
                $('#sub_category').append(opt1); //here we will append these new select options to a dropdown with the id 'cities'
                
            	
                $.each($subcategory,function(child_id,name) //here we're doing a foeach loop round each city with id as the key and city as the value
                {
                	var opt = $('<option />'); // here we're creating a new select option with for each city
                    opt.val(child_id);
                    opt.text(name);
                    $("#alert").html(opt).fadeIn('slow');
                    $('#sub_category').append(opt); //here we will append these new select options to a dropdown with the id 'cities'
                });
            }

        });

    });
});

/*GET KEYWORD BY SUB-CATEGORY -- (Rahul)*/

$(document).ready(function(){
    $('#sub_category').change(function(){ //any select change on the dropdown with id country trigger this code
        $("#keyword > option").remove(); //first of all clear select items
        var child_id = $('#sub_category').val();  // here we are taking country id of the selected one.
      
         $("#keyword").removeAttr('disabled');
       
         
        var base_url = $('body').data('baseurl');
        
       // var url = base_url+"browse/location/getcity/"+state_id
       // alert(url)
        var img = base_url + "assets/img/ajax-loader2.gif";
		$('#alert').html('<img src="' + img + '" />')
        
        $.ajax({
            type: "POST",
            url: base_url+"browse/category/getKeywords/"+child_id, //here we are calling our user controller and get_cities method with the country_id
            
            success: function($keywords) //we're calling the response json array 'cities'
            {
            	var opt1 = $('<option />'); // here we're creating a new select option with for each city
               opt1.val(0);
                opt1.text("---Select Keyword---");
                
                $('#keyword').append(opt1); //here we will append these new select options to a dropdown with the id 'cities'
                
            	
                $.each($keywords,function(child_id,name) //here we're doing a foeach loop round each city with id as the key and city as the value
                {
                	var opt = $('<option />'); // here we're creating a new select option with for each city
                    opt.val(child_id);
                    opt.text(name);
                    $("#alert").html(opt).fadeIn('slow');
                    $('#keyword').append(opt); //here we will append these new select options to a dropdown with the id 'cities'
                });
            }

        });

    });
});

/*
$(document).ready(function() {

	$("#submit_location").click(function() {

		 //alert(city_id);
		
		var base_url = $('body').data('baseurl');
		//alert ("Submitted");
		
		
		$.ajax({
			type : "GET",
			url : base_url + "browse/location/set_location",
		//	dataType : "json",
			data : $('#post_location_form').serialize(),
			success : function() {
			//	alert("Success");	
				$("#locationModal").modal('hide');
				document.location.reload();
			},
			error : function() {
				alert("failure");
			}
		});

	});
});
*/
/*
 
$(document).ready(function() {

	$("#submit_location").click(function() {

		var base_url = $('body').data('baseurl');

		var cityN = $('#cityN').val();

		$.ajax({
			type : "GET",
			url : base_url + "browse/location/set_location",
			dataType : "json",
			data : $('#post_location_form').serialize(),
			success : function(data) {
				// alert("Success");
				$("#locationModal").modal('hide');
				var cc = data.message;
				 alert(cc);
				// document.location.reload(data.message);
				// window.location.href= 'http://www.google.com';
				if (data != null) { // redirect...

					window.location.href = cc;

					// document.location.reload();
					// window.location.href= "http://www.google.com";
				} else { // report failure...

					alert("ERROR");

				}
			},
			error : function() {
				alert("failure");
			}
		});

	});
}); 
*/

$(document).ready(function() {

	$("#submit_location").click(function() {

		var base_url = $('body').data('baseurl');

		var curl = $('#curl').val();

		$.ajax({
			type : "GET",
			url : base_url + "browse/location/set_location",
			dataType : "json",
			data : $('#post_location_form').serialize(),
			success : function(data) {
				// alert("Success");
				$("#locationModal").modal('hide');
				var cc = data.message;
			//	 alert(cc);
				 document.location.reload(data.message);
				// window.location.href= 'http://www.google.com';
				if (data != null) { // redirect...

					window.location.href = cc;

					// document.location.reload();
					// window.location.href= "http://www.google.com";
				} else { // report failure...

					
					//$("#locationModal").modal('hide');
					//document.location.reload();
				alert("ERROR");

				}
			},
			error : function() {
				alert("failure");
			}
		});

	});
});


$(document).ready(function() {
	var base_url = $('body').data('baseurl');

	$("#clear").click(function() {

		//var url = base_url + "browse/location/clear_location";
		
		//alert(url);
		$.ajax({

			url : base_url + "browse/location/clear_location",
			success : function(response) {// response is value returned from
											// php (for your example it's "bye
											// bye"
				document.location.reload();
			}
		});

	});

});


function getlatlong() {
	$('#mymap').show();
	var geocoder = new google.maps.Geocoder();
	
	var street=$("#address").val();
	var state=$("#statediv option:selected").html();
	var city=$("#citydiv option:selected").html();
	
	//var address=country+','+state+','+city+','+street;
	var address=street+','+city+','+state;
	
	geocoder.geocode( { 'address': address}, function(results, status) {

	if (status == google.maps.GeocoderStatus.OK) {
    var latitude = results[0].geometry.location.lat();
	var longitude = results[0].geometry.location.lng();
	document.getElementById('lat').value=latitude;
	document.getElementById('long').value=longitude;
    } 

	
    var latlng = new google.maps.LatLng(latitude,longitude);
    var map = new google.maps.Map(document.getElementById('map'), {
        center: latlng,
        zoom: 14,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });
    var marker = new google.maps.Marker({
        position: latlng,
        map: map,
        title: 'Set lat/lon values for this property',
        draggable: true
    });
    google.maps.event.addListener(marker, 'dragend', function(a) {
        console.log(a);
       
        
		document.getElementById('lat').value = a.latLng.lat().toFixed(4);
		document.getElementById('long').value = a.latLng.lng().toFixed(4);
        document.getElementsByTagName('body')[0].appendChild(div);
    });
	}); 
};

function getlattlong() {
	$('#mymap2').show();
	var geocoder = new google.maps.Geocoder();
	
	var street=$("#address").val();
	var state=$("#statediv option:selected").html();
	var city=$("#citydiv option:selected").html();
	
	//var address=country+','+state+','+city+','+street;
	var address=street+','+city+','+state;
	
	geocoder.geocode( { 'address': address}, function(results, status) {

	if (status == google.maps.GeocoderStatus.OK) {
    var latitude = results[0].geometry.location.lat();
	var longitude = results[0].geometry.location.lng();
	document.getElementById('lat').value=latitude;
	document.getElementById('long').value=longitude;
    } 

	
    var latlng = new google.maps.LatLng(latitude,longitude);
    var map = new google.maps.Map(document.getElementById('map2'), {
        center: latlng,
        zoom: 14,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });
    var marker = new google.maps.Marker({
        position: latlng,
        map: map,
        title: 'Set lat/lon values for this property',
        draggable: true
    });
    google.maps.event.addListener(marker, 'dragend', function(a) {
        console.log(a);
       
        
		document.getElementById('lat').value = a.latLng.lat().toFixed(4);
		document.getElementById('long').value = a.latLng.lng().toFixed(4);
        document.getElementsByTagName('body')[0].appendChild(div);
    });
	}); 
};

matrix = {
		yp: {},
		
	};



//---SEND CLAIM REPORT---//
$(document).ready(function() {

	$("#btn_claim_submit").click(function() {
		var base_url = $('body').data('baseurl');
		var claim_name = $('#claim_name').val();
		var claim_email = $('#claim_email').val();
		var post_title = $('#post_title').val();
		var position_at = $('#position_at').val();
		//var description = $('#claim_description').val();
		
		var postData = {
			'claim_name' : claim_name,
			'claim_email' : claim_email,
			'post_title' : post_title,
			'position_at' : position_at,
	//		'claim_description' : description
		};

		//var url = base_url + "profile/claim_submit";
		//alert(url);
		
		var img = base_url + "assets/img/ico/ajax-loader-mini.gif";
		$('#claim_report').html('<img src="' + img + '" />')

		$.ajax({
			type : "POST",
			url : base_url + "profile/claim_submit",
			dataType : "json",
			data : postData,
			cache : false,
			success : function(data) {
				
			//	alert('aa');
				
				$("#claim_report").html(data.message).fadeIn('slow');
				$('#post_claim_form')[0].reset();
			}

		});
	});
});


//---SEND REPORT INCORRECT---//
$(document).ready(function() {

	$("#btn_report_submit").click(function() {
		
		
		var base_url = $('body').data('baseurl');
		var report_name = $('#report_name').val();
		var report_email = $('#report_email').val();
		var report_location = $('#report_location').val();
		var contact_no = $('#contact_no').val();
		var report_type = $('#report_type').val();
		var post_title = $('#post_title').val();
		var description = $('#description').val();
		
		var postData = {
			'report_name' : report_name,
			'report_email' : report_email,
			'post_title' : post_title,
			'report_location' : report_location,
			'contact_no' : contact_no,
			'report_type' : report_type,
			'description' : description,
		};

	//	alert(postData);
		
		
		
		var img = base_url + "assets/img/ico/ajax-loader-mini.gif";
		$('#report_msz').html('<img src="' + img + '" />')

		$.ajax({
			type : "POST",
			url : base_url + "profile/report_submit",
			dataType : "json",
			data : postData,
			
			
			
			cache : false,
			success : function(data) {
				$("#report_msz").html(data.message).fadeIn('slow');
				$('#post_report_form')[0].reset();
			}

		});
	});
});


//---SEND EMAIL TO FRIEND---//
$(document).ready(function() {

	$("#btn_email_submit").click(function() {
		
		
		var base_url = $('body').data('baseurl');
		var send_email = $('#send_email').val();
		var post_title = $('#post_title').val();
		var post_url = $('#post_url').val();
		var post_address = $('#post_address').val();
		var post_keyword = $('#post_keyword').val();
		
		var postData = {
			'send_email' : send_email,
			'post_title' : post_title,
			'post_url' : post_url,
			'post_address' : post_address,
			'post_keyword' : post_keyword,
		};

		
		var img = base_url + "assets/img/ico/ajax-loader-mini.gif";
		$('#email_msz').html('<img src="' + img + '" />')

		$.ajax({
			type : "POST",
			url : base_url + "profile/email_submit",
			dataType : "json",
			data : postData,
			cache : false,
			success : function(data) {
				$("#email_msz").html(data.message).fadeIn('slow');
				$('#post_send_form')[0].reset();
			}

		});
	});
});


